<?php

/**
 * This is the model class for table "comments".
 *
 * The followings are the available columns in table 'comments':
 * @property string $id
 * @property string $post_id
 * @property string $comment_author
 * @property string $comment_author_email
 * @property string $comment_author_url
 * @property string $comment_author_ip
 * @property string $comment_date
 * @property string $comment_content
 * @property string $comment_parent
 * @property integer $comment_approved
 * @property string $comment_karma
 * @property string $user_id
 */
class Comments extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Comments the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{comments}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('post_id, comment_author, comment_author_email, comment_content, user_id', 'required'),
            array('comment_author_email', 'email'),
            array('comment_approved', 'numerical', 'integerOnly' => true),
            array('post_id, comment_parent, comment_karma, user_id', 'length', 'max' => 11),
            array('comment_author, comment_author_email, comment_author_url', 'length', 'max' => 255),
            array('comment_author_ip', 'length', 'max' => 20),
            array('comment_date, comment_content', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, post_id, comment_author, comment_author_email, comment_author_url, comment_author_ip, comment_date, comment_content, comment_parent, comment_approved, comment_karma, user_id', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'post_id' => '文档',
            'comment_author' => '作者',
            'comment_author_email' => '作者邮箱',
            'comment_author_url' => '个人网址',
            'comment_author_ip' => '发布IP',
            'comment_date' => '发布时间',
            'comment_content' => '评论内容',
            'comment_parent' => '上级评论',
            'comment_approved' => '状态',
            'comment_karma' => '评分',
            'user_id' => '用户ID',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('post_id', $this->post_id);
        $criteria->compare('comment_author', $this->comment_author, true);
        $criteria->compare('comment_author_email', $this->comment_author_email, true);
        $criteria->compare('comment_author_url', $this->comment_author_url, true);
        $criteria->compare('comment_author_ip', $this->comment_author_ip);
        $criteria->compare('comment_date', $this->comment_date, true);
        $criteria->compare('comment_content', $this->comment_content, true);
        $criteria->compare('comment_parent', $this->comment_parent, true);
        $criteria->compare('comment_approved', $this->comment_approved);
        $criteria->compare('comment_karma', $this->comment_karma, true);
        $criteria->compare('user_id', $this->user_id);
        $criteria->order = 'id DESC';

        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                    'pagination' => array(
                        'pageSize' => 20,
                    )
                ));
    }

}